
<template>
  <div class="anchorbox" @click="linkTo">
    <div class="flex anchorbox-top  pointer">
      <div class="anchorbox-top-img">
        <img
          class="header"
          onerror="javascript:this.src='https://kunheng-web-static.oss-cn-hangzhou.aliyuncs.com/hongjiv3.0/icon/logo_xcc.png'"
          :src="anchor.headerImage"
          alt=""
        >
        <img class="icon" :src="anchor.anchorGrade | anchorIcon" alt="">
      </div>
      <div class="anchorbox-top-center">
        <div class="name ellipsis">
          <router-link
            class="a_sham"
            :to="{
              name: linkToName,
              params: {
                anchorId: anchor.anchorId,
                platformType: anchor.platformType
              }
            }"
            target="_blank"
            @click.native.stop="storeAnchor"
          >
            {{ anchor.anchorName }}
          </router-link>
        </div>
        <div class="fans">{{ anchor.fansNum | f_number(1) }}粉丝</div>
      </div>
      <div class="anchorbox-top-right">
        <div class="platform flex">
          <img class="logo" :src="anchor.platformType | platformType">
          <!--          <div class="score">{{ anchor.anchorScore | strDataFil }}分</div>-->
        </div>
        <div v-if="anchor.isVerify" class="vertify flex">
          <i class="iconfont icon-yijingrenzheng" />
          <span>已认证</span>
        </div>
      </div>
    </div>
    <div class="anchorbox-cont">
      <div class="anchorbox-cont-zhibo">
        <div class="flex">
          <div>
            <div class="flex flex-align-center excel">
              <div class="line" />
              <div class="tit1">擅长类目</div>
              <div class="line line-right" />
            </div>
            <div v-if="anchor.goodCategory" class="flex classes">
              <div
                v-for="it in anchor.goodCategory.split(',')"
                :key="it"
                class="classes-item"
              >
                {{ it }}
              </div>
            </div>
            <div v-else class="classes-no">暂无擅长类目</div>
          </div>
        </div>
        <div class="flex" style="margin-top: 18px">
          <div>
            <div class="medium ellipsis">
              {{ anchor.totalSaleVolume | f_number(2, { fen: true }) }}
            </div>
            <div class="tit">近日直播销售额</div>
          </div>
          <div>
            <div class="medium ellipsis">
              {{
                anchor.serviceFeeMin
                  | minMax(anchor.serviceFeeMax, { unit: true })
              }}
            </div>
            <div class="tit">服务费</div>
          </div>
          <div>
            <div class="medium ellipsis">
              {{
                anchor.commissionPercentMin
                  | minMax(anchor.commissionPercentMax, { fen: false })
              }}%
            </div>
            <div class="tit">佣金要求</div>
          </div>
        </div>
      </div>
    </div>
    <div class="anchorbox-btn">
      <LoginDialog v-if="anchor.isVerify || anchor.anchorType === 0" :title="'立即报名'" :path-name="pathName" :path-data="pathData" />
      <div v-else class="anchorbox-btn-anc" @click.stop="linkTo">
        联系主播
      </div>
    </div>
  </div>
</template>

<script>
import { localStorage } from 'common/storage'
export default {
  props: {
    anchor: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      list: [{ label: '直播' }, { label: '佣金' }],
      actindex: 0,
      pathName: 'hjAnchorSignUp',
      pathData: {
        anchorId: this.anchor.anchorId,
        platformType: this.anchor.platformType
      }
    }
  },
  computed: {
    linkToName() {
      if (this.$route.name === 'hjOrganDataDetail') {
        return 'hjAnchorDataDetail'
      } else {
        return 'hjAnchorDetail'
      }
    }
  },
  watch: {
    anchor: {
      handler(v) {
        this.actindex = 0
        this.pathData.anchorId = this.anchor.anchorId
        this.pathData.platformType = this.anchor.platformType
      },
      immediate: true,
      deep: true
    }
  },
  created() {},
  methods: {
    // tab 切换
    tabChange(v) {
      this.actindex = v
    },
    storeAnchor() {
      let arr = localStorage.get('viewAnchor') || []
      const viewIdx = arr.findIndex(it => it === this.anchor.lxAnchorRelayId)
      if (viewIdx !== -1) {
        arr.splice(viewIdx, 1)
      }
      arr = arr.slice(0, 9) // 删除重复主播并截取缓存前9个，最多缓存10条主播信息
      arr.unshift(this.anchor.lxAnchorRelayId)
      localStorage.set('viewAnchor', arr)
    },
    linkTo() {
      this.storeAnchor()
      const url = this.$router.resolve({
        name: this.linkToName,
        params: {
          anchorId: this.anchor.anchorId,
          platformType: this.anchor.platformType
        }
      })
      window.open(url.href, '_blank')
    }
  }
}
</script>

<style scoped lang="scss">
.anchorbox {
  line-height: 1;
  cursor: pointer;
  width: 288px;
  height: 255px;
  padding: 18px 18px 14px;
  // margin-right: 26px;
  border: 1px solid transparent;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  &-top {
    justify-content: space-between;
    &-img {
      width: 58px;
      height: 58px;
      margin-right: 10px;
      position: relative;
      .header {
        border-radius: 50%;
        width: 58px;
        height: 58px;
      }
      .icon {
        position: absolute;
        width: 27px;
        height: 16px;
        right: 0;
        bottom: 0;
      }
    }
    &-center {
      width: 105px;
      padding: 9px 0;
      .name {
        font-size: 16px;
        color: #333;
        line-height: 20px;
        margin-bottom: 10px;
        font-weight: 500;
      }
      .fans {
        color: #666;
      }
    }
    &-right {
      margin-left: 7px;
      padding: 7px 0;
      width: 72px;
      .platform {
        float: right;
        margin-bottom: 10px;
        align-items: center;
        justify-content: space-between;
        .logo {
          width: 20px;
          height: 20px;
          border-radius: 50%;
        }
        .score {
          color: #ff0929;
        }
      }
      .vertify {
        display: inline-block;
        width: 70px;
        height: 18px;
        border-radius: 10px;
        border: 1px solid #ff4909;
        color: #ff4909;
        padding: 0 6px;
        font-size: 13px;
        line-height: 16px;
        text-align: center;
        i {
          font-size: 14px;
          margin-right: 3px;
        }
      }
    }
  }
  &-tab {
    margin-top: 10px;
    position: relative;
    display: flex;
    font-size: 13px;
    &-item {
      color: #666;
      cursor: pointer;
      padding-bottom: 2px;
      margin-right: 14px;
      &:nth-child(2) {
        margin-right: 0;
      }
      // &:hover {
      //   color: #ff0929;
      // }
    }
    &-active {
      color: #ff0929;
      position: relative;
      &::after {
        content: '';
        width: 16px;
        height: 1px;
        position: absolute;
        bottom: -4px;
        left: 5px;
        background: #ff0929;
      }
    }
    &::after {
      content: '';
      position: absolute;
      width: 176px;
      height: 1px;
      background: #f4f4f4;
      right: 0;
      top: 7px;
    }
  }
  &-cont {
    margin: 9px 0px 14px;
    border-radius: 6px;
    color: #333;
    font-size: 12px;
    .line {
      width: 91px;
      height: 1px;
      background-image: linear-gradient(to right, #fff, #e4e4e4);
    }
    .line-right {
      background-image: linear-gradient(to left, #fff, #e4e4e4);
    }
    .tit1 {
      color: #999;
      width: 57px;
      margin: 0 7px;
      font-size: 14px;
    }
    .tit {
      color: #666;
      font-size: 12px;
      margin-top: 6px;
    }
    &-zhibo,
    &-yongjin {
      > div {
        justify-content: space-around;
        text-align: center;

      }
      .excel {
        line-height: 14px;
        margin-bottom: 14px;
      }
      .medium {
        max-width: 83px;
        font-size: 16px;
        color: #333;
        font-weight: 500;
      }
      .remark {
        margin-bottom: 8px;
      }
      .classes {
        justify-content: space-around;
        &-item {
          height: 23px;
          font-size: 14px;
          border-radius: 100px;
          padding: 4px 7px;
          &:nth-child(1) {
            background: rgba(255, 9, 41, 0.08);
            color: #ff0929;
          }
          &:nth-child(2) {
            background: rgba(255, 100, 27, 0.08);
            color: #ff641b;
          }
          &:nth-child(3) {
            background: rgba(110, 111, 255, 0.08);
            color: #6464ff;
          }
        }
        &-no {
          line-height: 21px;
        }
      }
    }
  }
  &-btn {
    width: 212px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    margin: 0 auto;
    font-weight: 500;
    cursor: pointer;
    &-sign,
    &-anc {
      margin: 0 auto;
      font-weight: 500;
      color: #ff0929;
      width: 212px;
      height: 32px;
      // line-height: 30px;
      line-height: 1;
      padding: 8px 0;
      border-radius: 17px;
      text-align: center;
      border: 1px solid #ff0929;
    }
  }
}
/deep/ .el-checkbox__label {
  font-weight: 400;
}
.anchorbox:hover {
  border: 1px solid #ff0929;
  // height: 290px;
  // margin: -19px 0 7px;
  // .anchorbox-btn {
  //   display: block;
  // }
}
</style>
